package com.rescue.controller.user;

import com.rescue.context.BaseContext;
import com.rescue.forum.dto.ApplyDTO;
import com.rescue.forum.entity.RescueMan;
import com.rescue.result.Result;
import com.rescue.service.RescueManService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user/rescue")
@RestController("RescueController")
@Api(tags = "救援相关接口")
@Slf4j
public class RescueController {
    @Autowired
    private RescueManService rescueManService;
    /**
     * 根据userId获取救援用户信息
     * @param
     * @return
     */
    @ApiOperation("根据userId获取救援用户信息")
    @GetMapping("/getById")
    private Result<RescueMan> getById(Integer userId){
        log.info("根据userId获取救援用户信息:{}", userId);
        RescueMan rescueMan = rescueManService.getById(userId);
        return Result.success(rescueMan);
    }

    /**
     * 修改用户信息
     * @param rescueMan
     * @return
     */
    @ApiOperation("修改用户救援信息")
    @PostMapping("/update")
    private Result update(@RequestBody RescueMan rescueMan){
        log.info("修改用户信息：{}",rescueMan);
        rescueManService.update(rescueMan);
        return Result.success();
    }

    /**
     * 申请为救援者
     * @param applyDTO
     * @return
     */
    @ApiOperation("申请为救援者")
    @PostMapping("/apply")
    private Result apply(@RequestBody ApplyDTO applyDTO){
        log.info("申请成为救援者：{}",applyDTO);
        rescueManService.apply(applyDTO);
        return Result.success();
    }
}
